//
//  THJCompanyProductView.m
//  THJXHW
//
//  Created by 河南德艺 on 2017/11/2.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJCompanyProductView.h"
#import "THJDataProduceCell.h"
#import "ZBNetworking.h"
@implementation THJCompanyProductView
{
    NSArray * listArr;
    UITableView * _tableview;
}

-(instancetype)initWithId:(NSString*)TheId{
    if(self = [super init]){
        [self getDataWithCid:TheId];
    }
    return self;
}
-(void)getDataWithCid:(NSString*)cid{

    [ZBRequestManager requestWithConfig:^(ZBURLRequest *request){
        NSString * url = [NSString stringWithFormat:@"%@index.php?f=sell_5&r=sell_5&cid=%@",THJUrlDomain,cid];
        NSLog(@"url-%@",url);
        request.urlString = url;
        request.apiType=ZBRequestTypeCache;
    }  success:^(id responseObject,apiType type){
        NSDictionary * receiveData = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        if([receiveData[@"status"] isEqual:@"200"]){
            NSLog(@"K-receiveData-%@",receiveData);
            listArr = receiveData[@"data"];
            [self setUI];
        }
    } failed:^(NSError *error){
    }];
}
-(void)setUI{
    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, self.frame.size.height) style:UITableViewStylePlain];
    [_tableview registerNib:[UINib nibWithNibName:@"THJDataProduceCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    _tableview.tableFooterView = [UIView new];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.rowHeight = 110;
    [self addSubview:_tableview];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return listArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic = listArr[indexPath.row];
    THJDataProduceCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    [cell setCellContentWithDic:dic];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary * dic = listArr[indexPath.row];
    NSLog(@"itemid-o-%@",dic[@"itemid"]);
    [self.delegate cellClickedItemid:dic[@"itemid"]];
}
@end
